{extend name='admin@main'}

{block name="button"}

{if auth("add_holiday")}
<!-- <button data-open='{:url("add_holiday")}' data-title="我要休假" class='layui-btn layui-btn-sm layui-btn-primary'>我要休假</button> -->
{/if}

{/block}




{block name="content"}

    

    <div class="panel panel-default">   
      
      <div class="panel-body">
        <div id='calendar'></div>
      </div>

    </div>


{/block}


{block name='script'}
<link href="__ROOT__/static/bootcss/bootstrap.min.css" rel="stylesheet">
<!-- <script src='__ROOT__/static/plugs/calendar/js/jquery-1.10.2.js'></script>  -->
<!-- <script src="https://cdn.bootcss.com/moment.js/2.0.0/lang/zh-cn.min.js"></script> -->
<!-- <script src="https://cdn.bootcss.com/moment.js/2.0.0/langs.min.js"></script> -->
<!-- <script src="https://cdn.bootcss.com/moment.js/2.24.0/moment.min.js"></script> -->
<!-- <script src='__ROOT__/static/plugs/calendar/js/moment.js'></script>  -->

<script src='__ROOT__/static/plugs/calendar/js/fullcalendar.min.js'></script>
<link rel="stylesheet" type="text/css" href="__ROOT__/static/plugs/calendar/css/fullcalendar.css">

<!-- <link href='__ROOT__/static/plugs/calendar/dist/fullcalendar.css' rel='stylesheet' />
<link href='__ROOT__/static/plugs/calendar/dist/fullcalendar.print.css' rel='stylesheet' media='print' /> -->
<!-- <script src='__ROOT__/static/plugs/calendar/dist/fullcalendar.js'></script> -->

<script src="__ROOT__/static/plugs/calendar/ui/jquery.ui.core.js"></script>
<script src="__ROOT__/static/plugs/calendar/ui/jquery.ui.widget.js"></script>
<script src="__ROOT__/static/plugs/calendar/ui/jquery.ui.mouse.js"></script>
<script src="__ROOT__/static/plugs/calendar/ui/jquery.ui.position.js"></script>
<script src="__ROOT__/static/plugs/calendar/ui/jquery.ui.draggable.js"></script>
<script src="__ROOT__/static/plugs/calendar/ui/jquery.ui.resizable.js"></script>
<script src="__ROOT__/static/plugs/calendar/ui/jquery.ui.droppable.js"></script>
<script type="text/javascript">




layui.use(['form', 'layedit', 'laydate','jquery','layer'], function(){

    var $ = layui.$ 
    ,layer = layui.layer;

        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();

		$('#calendar').fullCalendar({
        header: {
            left: 'prev,next today ',
            center: 'title',
            right: 'year,month,agendaWeek,agendaDay'
        },
		buttonText: {

			prevYear: '«', // «
			nextYear: '»', // »
			
			today: '今天',
			month: '月视图',
			week: '周视图',
			day: '日视图'
		},
		
		titleFormat: {
			month: 'yyyy年 MMMM月',
			week: "[yyyy年] MMMM月d日 { '&#8212;' [yyyy年] MMMM月d日}",
			day: 'yyyy年 MMMM月d日 dddd'
		},
		
		monthNames: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
		dayNames: ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
		
        defaultView: 'month',
        firstDay:1,
        theme:false,
        editable: true,
        timeFormat: 'H:mm(T)',
        axisFormat: 'H:mm(T)',
        width:'960',
        height:'840',
        firstHour:'8',
        //weekNumbers: true,
        businessHours: true,
        dragOpacity: {
            agenda: .5,
            '':.6
        },

	/*
            events: [
                {
                    title: '全天计划\r\n#####\r\n写代码',
                    start: new Date(y, m, 1)
                }
            ],
			
		*/
        
        //拖拽，不改变大小
        eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {
            //layer.msg(minuteDelta);
            //console.log(event);
            $.post("{:url("Calendar/draglog")}",{id:event.id,daydiff:dayDelta,minudiff:minuteDelta,allday:allDay},function(res){
				//console.log(res);
				//console.log(res);
                if(res.code =='0'){				
					layer.msg(res.info);
					//location.reload();
                    //alert(msg);
                    //alert("Drag");
                    //$(this).navtab('reload');
                    //revertFunc();
                }
            });
            
        },
        
        //改变大小
        eventResize: function(event,dayDelta,minuteDelta,revertFunc) {
            //alert(dayDelta);
			//console.log(event.id+event.title);
            
            $.post("{:url("resize")}",{id:event.id,daydiff:dayDelta,minudiff:minuteDelta},function(res){
				//layer.msg(res.info);
                //$(this).navtab('reload');
				//location.reload();
				//console.log(res);
                if(res.code =='0'){				
					layer.msg(res.info);
					//location.reload();
                    //alert(msg);
                    //alert("Drag");
                    //$(this).navtab('reload');
                    //revertFunc();
                }
            });
            
        },
        
        
        selectable: true,
        select: function( startDate, endDate, allDay, jsEvent, view ){
            var start =$.fullCalendar.formatDate(startDate,'yyyy-MM-dd HH:mm:ss');
            var end =$.fullCalendar.formatDate(endDate,'yyyy-MM-dd HH:mm:ss');
            //alert(end);
			
			layer.open({
				type:2,
				id: 'addnew',
				content: ['{:url("add")}?date='+start+'&end='+end, 'yes'],
				//content:'/admin.html#/{:url("add")}?&date='+selDate,
				area: ['650px', '500px'],
                title:'新建日程',
                onClose:'refeshTab',
				//btn:['保存','取消'],
				closeBtn:1,
				move:'#aaa',
				yes:function(index,layero)
				{	

		
					
					//当你在iframe页面关闭自身时
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					//console.log(index);
					//layer.closeAll('page'); //关闭所有页面层
					//parent.layer.close(index); //再执行关闭 
					
					layer.close(index);//需手动关闭 弹出层
				},
				no:function(index,layero)
				{
					layer.msg('no');
					layer.close(index);//需手动关闭 弹出层
				},			
				btn2:function(index,layero){
					layer.msg('btn2');
					//不需要手动关闭 弹出层
				},
				btn3:function(index,layero){
					layer.msg('btn3');
					//不需要手动关闭 弹出层
				}
			})


            //$(this).navtab('reload');
        },
        
        //events:{$data},
        
        
        events: '{:url("getJson")}',
		
		//点击新增
        dayClick: function(date, allDay, jsEvent, view) {
            var selDate =$.fullCalendar.formatDate(date,'yyyy-MM-dd HH:mm:ss');
            //alert(selDate);
			
			
			layer.open({
				type:2,
				id: 'addnew',
				content: ['{:url("add")}?date='+selDate, 'no'],
				area: ['750px', '600px'],
                title:'新建日程',
                onClose:'refeshTab',
				//btn:['保存','取消'],
				//btn:['保存','取消','按钮三'],

				closeBtn:1,
				move:'#aaa',
				yes:function(index,layero)
				{	
					//layer.msg(color);
					
					var color = $("#color").val();
					layer.msg(color);
					return false;
					
					$.ajax({
						type: "POST",
						url: '{:url("add")}',
						data: data,
						success: function (msg) {
							if (msg.code == "1") {
								location.reload();
							}else {
								layer.msg('失败')
							}
						},error: function () {
							alert("出现错误");
							return false;
						}
					}); //ajax结束
		
					
					
					
					//当你在iframe页面关闭自身时
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					//console.log(index);
					//layer.closeAll('page'); //关闭所有页面层
					//parent.layer.close(index); //再执行关闭 
					
					layer.close(index);//需手动关闭 弹出层
				},
				no:function(index,layero)
				{
					layer.msg('no');
					layer.close(index);//需手动关闭 弹出层
				},			
				btn2:function(index,layero){
					layer.msg('btn2');
					//不需要手动关闭 弹出层
				},
				btn3:function(index,layero){
					layer.msg('btn3');
					//不需要手动关闭 弹出层
				}
			})
			
			

            
        },
        
        
        eventClick: function(calEvent, jsEvent, view) {
        
            //alert('Event: ' + calEvent.id);
			
			//询问框
			var id=calEvent.id;

			var index = layer.open({
				type:2,
				id: 'addnew',
				content: ['{:url("edit")}?id='+id, 'no'],
				//content:'/admin.html#/{:url("add")}?&date='+selDate,
				area: ['750px', '600px'],
                title:'新建日程',
                onClose:'refeshTab',
				//btn:['保存','取消'],
				//btn:['保存','取消','按钮三'],

				closeBtn:1,
				move:'#aaa',
				yes:function(index,layero)
				{	
					//layer.msg(color);
					
					var color = $("#color").val();
					layer.msg(color);
					return false;
					
					$.ajax({
						type: "POST",
						url: '{:url("edit")}',
						data: data,
						success: function (msg) {
							if (msg.code == "1") {
								location.reload();
							}else {
								layer.msg('失败')
							}
						},error: function () {
							alert("出现错误");
							return false;
						}
					}); //ajax结束
		
					
					
					
					//当你在iframe页面关闭自身时
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					//console.log(index);
					//layer.closeAll('page'); //关闭所有页面层
					//parent.layer.close(index); //再执行关闭 
					
					layer.close(index);//需手动关闭 弹出层
				},
				no:function(index,layero)
				{
					layer.msg('no');
					layer.close(index);//需手动关闭 弹出层
				},			
				btn2:function(index,layero){
					layer.msg('btn2');
					//不需要手动关闭 弹出层
				},
				btn3:function(index,layero){
					layer.msg('btn3');
					//不需要手动关闭 弹出层
				}
			})

			/*

			layer.confirm('id'+id+':'+calEvent.title, {
				btn: ['删除','关闭'] //按钮
			}, function(){
				$.post("{:url("delete")}",{id:id},function(msg){
					layer.msg('删除成功！'+id, {icon: 1});
					parent.location.reload();
				});
			}, function(){
			
			});
			
			*/
			
			
            //alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
            //alert('View: ' + view.name);
            // change the border color just for fun
            //$(this).css('border-color', 'red');
            
            

        }
    });
    
});
</script>




{/block}